home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dskut
/
part.zip
/
PART.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-27
|
28KB
|
818 lines
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <conio.h>
#include <bios.h>
char version[] = "Version: Mk 1.5 27 October 1993" ;
#define FALSE 0
#define TRUE 1
#define LOC_PT 0x1BE
#define LOC_NT 0x1AA
#define LOC_GWR 0x1A9
#define MAGIC_LOC 0x1FE
#define MAGIC_0 0x55
#define MAGIC_1 0xAA
#define NT_ENTRY_SIZE 5
#define SECSIZE 0x200
#define sw_printf if (sw_fancy) printf
struct disk_param {
unsigned int cyl ;
unsigned int head ;
unsigned int sect ;
};
/* Global variables */
int sw_help = FALSE, sw_null = FALSE, sw_number = FALSE ;
int sw_bios = FALSE, sw_ide = FALSE, sw_details = FALSE, sw_fancy = TRUE ;
unsigned int device = 0 ;
/* MAIN PROGRAM --- MAIN PROGRAM --- MAIN PROGRAM --- MAIN PROGRAM */
int main (argc, argv)
/***************************************************************/
/* */
/* --- Partition Table and Hard Disk Examination Program --- */
/* */
/* Some code used by this program was derived from: */
/* Pfdisk, Version 1.2.1 by Gordon W. Ross, Aug. 1990 */
/* and later modified by S. Lubkin Oct. 1991 */
/* Dug_ide, Version 1.0 by Doug Merrett, 12 Jan 1993 */
/* */
/* Both programs like this program are public domain freeware. */
/* */
/* (c) Copyright 1993 by Gary A. Allen, Jr. */
/* Program written by Gary A. Allen, Jr. */
/* Version: Mk 1.5 27 October 1993 */
/* */
/***************************************************************/
int argc ;
char *argv[] ;
{
register int i, j ;
int num_drv_bios, num_drv_act ; /* Number of Hard disks */
int useNTable; /* boot sector uses name table */
int cyl_bgn[4], cyl_lst[4], head_bgn[4], head_end[4] ;
int sect_bgn[4], sect_end[4], type_code[4] ;
int sw_active[4] ;
unsigned int dd[256]; /* Disk Data */
unsigned int pbc,pbh,pbs; /* physical beginning c,h,s */
unsigned int pec,peh,pes; /* physical ending c,h,s */
char chr, cmd[8] ;
char *prt_nam[4], *output_string ;
char buffer[SECSIZE]; /* The boot block buffer */
char *active;
long sect_str[4], sect_lng[4] ;
unsigned long lsbeg,lslen; /* logical sectors: begin, length */
static char fancy1[81] = {
0xc9,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xd1,0xcd,0xcd,
0xcd,0xcd,0xd1,0xcd,0xcd,0xcd,0xcd,0xd1,0xcd,0xcd,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xd1,0xcd,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xd1,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xd1,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xbb,
0} ;
static char fancy2[] =
"\xba Part \xb3" "Type\xb3" "Boot\xb3" " Beginning"
" \xb3" " Ending \xb3"
"Starting \xb3" "Number of\xba" ;
static char plain1[] =
" Part Type Boot Beginning Ending "
"Starting Number of\n" ;
static char fancy3[] =
"\xba" " Type \xb3" "Code\xb3" "Part\xb3" "Side Cylinder Sector\xb3"
"Side Cylinder Sector\xb3"
" Sector \xb3" " Sectors \xba";
static char plain2[] =
" Type Code Part Side Cylinder Sector "
"Side Cylinder Sector Sector Sectors \n";
static char fancy4[81] = {
0xcc,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xd8,0xcd,0xcd,
0xcd,0xcd,0xd8,0xcd,0xcd,0xcd,0xcd,0xd8,0xcd,0xcd,
0xcd,0xcd,0xd1,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,
0xcd,0xd1,0xcd,0xcd,0x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xcd,0xcd,0xcd,0xcd,0xcd,0xcf,0xcd,
0xcd,0xcd,0xcd,0xcf,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,
0xcd,0xcd,0xcf,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcf,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcf,
0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xcd,0xbc,
0} ;
struct part { /* An entry in the partition table */
unsigned char active; /* active flag (0x80 or 0) */
unsigned char b_head; /* begin head */
unsigned char b_sect ; /* sector */
unsigned char b_cyl; /* cylinder */
unsigned char sysid; /* system id */
unsigned char e_head; /* end head */
unsigned char e_sect ; /* end sector */
unsigned char e_cyl; /* end cylinder */
/* These two are just longs, but this way is machine independent. */
unsigned long lsBeg; /* logical sectors, beginning */
unsigned long lsLen; /* logical sectors, length */
} *pp ; /* partition table entry */
struct disk_param dk, lg, le ;
/* Function Prototype */
int getGeometry(int, struct disk_param*) ;
int getBBlk(int, char*) ;
char *getascii(unsigned int in_data[], int off_start, int off_end);
char *nameID(unsigned int);
void listPTable(void) ;
void long2chs(unsigned long, struct disk_param*, struct disk_param*) ;
void switch_list(void) ;
void cmd_switch(char, int, char *[]) ;
void bugs(void), help(void) ;
/* Print heading */
printf(" ") ;
printf(" --- Partition Table and Hard Disk Examination Program ---\n") ;
printf(" ") ;
printf(" Program written by Gary A. Allen, Jr. \n") ;
printf(" ") ;
printf(" %s\n",version) ;
printf(" ") ;
printf("(c) Copyright 1993 by Gary A. Allen, Jr.\n\n") ;
/* Scan the after the dos command PART.EXE for switches or file name */
if (argc > 1) {
for (i = 1; i <= argc-1; i++) {
/* Flush command vector */
for (j = 0; j <= 7; j++) cmd[j] = '\0' ;
/* Get command vector */
sscanf(argv[i],"%c%c%c%c%c%c%c%c%c", &chr, &cmd[0], &cmd[1],
&cmd[2], &cmd[3], &cmd[4], &cmd[5], &cmd[6], &cmd[7]) ;
sw_null = FALSE ;
if (chr == '?') help() ;
if (chr == '-') {
for (j = 0; j <= 7; j++) {
cmd_switch(cmd[j], i, argv) ;
if (sw_number) {
i++ ;
sw_number = FALSE ;
break ;
}
if (sw_null) break ;
} /* end of command "for" loop */
if (j >= 7) {
printf("\n!!!! Too many commands on one \"-\" switch group.\n") ;
printf("!!!! Break up the commands into several \"-\" switch groups.\n") ;
bugs() ;
}
} /* end of the "-" marker block */
/* Deal with garbage on the command line */
else {
printf ("\n!!!! The following on the command line was not understood: %s \n",
argv[i]);
bugs() ;
} /* garbage block */
} /* end of argument token "for" loop */
if (sw_help) help() ;
} /* end of the command switch block */
/* determine actual number of disk drives */
num_drv_act = 0 ;
while (!getGeometry(num_drv_act++,&dk)) ;
num_drv_act-- ;
if (num_drv_act == 0) {
printf("!!!! There is no hard disk on this computer!\n") ;
bugs() ;
}
/* State the drive number */
if (num_drv_act != 1) printf("Describing hard disk #%d\n", device);
/* Ask BIOS how many disk drives there are */
/* Byte at Segment 40H Offset 75H */